package com.moleq.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.moleq.mgpos.activities.R;

public class MenuColorAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private String[] Source;
	private int selectedRow = 0;
	private static final int Bule = 0;
	private static final int Green = 1;
	private static final int Orange = 2;
	private static final int Red = 3;
	private static final int Gray = 4;
	private Drawable d_bule, d_green, d_orange, d_red, d_gray;

	public MenuColorAdapter(Context context) {
		this.mInflater = LayoutInflater.from(context);
		d_bule = context.getResources().getDrawable(R.drawable.button_1);
		d_green = context.getResources().getDrawable(R.drawable.button_2);
		d_orange = context.getResources().getDrawable(R.drawable.button_3);
		d_red = context.getResources().getDrawable(R.drawable.button_4);
		d_gray = context.getResources().getDrawable(R.drawable.button_5);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 5;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.user_color_items, null);
			holder.ll_user_color_item = (LinearLayout) convertView
					.findViewById(R.id.ll_user_color_item);
			holder.iv_user_color_item = (ImageView) convertView
					.findViewById(R.id.iv_user_color_item);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		switch (position) {
		case Bule:
			holder.iv_user_color_item.setImageDrawable(d_bule);
			break;
		case Green:
			holder.iv_user_color_item.setImageDrawable(d_green);
			break;
		case Orange:
			holder.iv_user_color_item.setImageDrawable(d_orange);
			break;
		case Red:
			holder.iv_user_color_item.setImageDrawable(d_red);
			break;
		case Gray:
			holder.iv_user_color_item.setImageDrawable(d_gray);
			break;

		default:
			break;
		}
		if (position == selectedRow) {
			holder.ll_user_color_item.setBackgroundColor(Color
					.rgb(255, 219, 16));
		} else {
			holder.ll_user_color_item.setBackgroundColor(Color.rgb(204, 204,
					204));
		}

		return convertView;
	}

	public final class ViewHolder {
		public LinearLayout ll_user_color_item;
		public ImageView iv_user_color_item;
	}

	public void ScrollToRow(int row) {
		selectedRow = row;
		this.notifyDataSetChanged();
	}

	public int GetSelectedIndex() {
		return selectedRow;
	}

	public Drawable getColorDrawable() {
		switch (selectedRow) {
		case Bule:
			return d_bule;
		case Green:
			return d_green;
		case Orange:
			return d_orange;
		case Red:
			return d_red;
		case Gray:
			return d_gray;
		default:
			return d_bule;
		}
	}
}
